"""

若通过链表实现，让链表尾部指针的pnext，
指向头指针，即用链表实现循环队列
"""


class CircleQueue:
    def __init__(self,max_size):
        self.max_size = max_size
        self.arr = [0] * max_size
        self.front = 0
        self.rear = 0

    def en_queue(self,element):
        #判断队列是否满
        if (self.rear + 1) % self.max_size == self.front:
            print('队列满了')
            return False
        self.arr[self.rear] = element #f放入循环队列
        self.rear = (self.rear + 1)%self.max_size
        return True

    def de_queue(self):
        if self.front == self.rear:
            print('队列为空')
            return False
        element = self.arr[self.front]
        self.front = (self.front + 1) %self.max_size
        return element

if __name__ == '__main__':
    c = CircleQueue(5)
    c.en_queue(1)
    c.en_queue(2)
    c.en_queue(3)
    c.en_queue(4)
    c.en_queue(5)
    print(c.de_queue())










